.PHONY: build clean api statics
VERSION := $(shell git rev-parse --abbrev-ref HEAD)
IMAGE_NAME := registry.cn-zhangjiakou.aliyuncs.com/aarch/apibe-rome:$(VERSION)

linux:export GOOS=linux
linux:export GOARCH=amd64
linux:export GODEBUG=cgocheck=0

linux-arm:export GOOS=linux
linux-arm:export GOARCH=amd64
linux-arm:export GODEBUG=cgocheck=0

windows:export GOOS=windows
windows:export GOARCH=amd64
windows:export CGO_ENABLED=0

linux: build
linux-arm: build

windows: build
	@mv build/ndr-mapping build/ndr-mapping.exe

build: clean
	@echo "Compiling source"
	go build -o build/rome main.go

clean:
	@echo "Clean source"
	@rm -rf build
	@mkdir -p build

micro: build
	@echo "docker image $(IMAGE_NAME)"
	@cp config-micro.yml build/config.yml
	@cp Dockerfile build
	docker image inspect $(IMAGE_NAME) > /dev/null 2>&1 && docker rmi $(IMAGE_NAME) || true
	docker build -t $(IMAGE_NAME) -f build/Dockerfile .
	docker push $(IMAGE_NAME)


commit: linux
	@ssh apibe "rm -rf /root/apibe/rome/rome"
	@scp build/rome apibe:/root/apibe/rome
	@ssh apibe "docker restart apibe-rome"

deploy: commit